module evt {
	/**
	 * 简单事件
	 * @author deta_lee
	 * version egret 2.5.1+
	 * 
	 */
	export function $on(eventName:String,handler?:any,thisObj?:any){
		if(handler==null || handler==undefined)handler=null;
		if(thisObj==null||thisObj==undefined) thisObj=this;
		this.MyEventDispatcher.getInstance().addEventListener(eventName,handler,thisObj);
		return this;
	}
	export function $off(eventName:any,handler?:any,thisObj?:any){
		var eventMap=this.MyEventDispatcher.getInstance().$getEventMap();
		if(thisObj==null||thisObj==undefined) thisObj=this;
		if(handler==null||handler==undefined){
			var eveList=eventMap[eventName];
			var len=eveList.length;
			for(var i=0;i<len;i++){
				// 清空事件数组
				this.MyEventDispatcher.getInstance().removeEventListener(eventName,eveList[0].listener,thisObj);
			}
		}else{
			this.MyEventDispatcher.getInstance().removeEventListener(eventName,handler,thisObj);
		}
		return this;		
	}
	export function $once(eventName:String,handler?:any,thisObj?:any){
		if(handler==null || handler==undefined)handler=null;
		if(thisObj==null||thisObj==undefined) thisObj=this;
		this.MyEventDispatcher.getInstance().once(eventName,handler,thisObj);
		return this;		
	}
	export function $emit(evetName:string,paramObj?:any){
		var newEvent:MyEvent = new MyEvent(evetName);
		if(paramObj== null || paramObj== undefined) paramObj=null;
        newEvent.paramObj = paramObj;
		this.MyEventDispatcher.getInstance().dispatchEvent(newEvent);
		return this;		
	}
	export class MyEvent extends egret.Event{
		public paramObj:any; //可用于传递参数
		public handleList:Array<any>=[];
		public constructor(type:string,handle:any=undefined,bubbles:boolean=false, cancelable:boolean=false) {
			super(type,bubbles,cancelable);
		}
	}
	export class MyEventDispatcher extends egret.EventDispatcher{
    	private static _instance:MyEventDispatcher;
		public constructor() {super();}
		public static getInstance():MyEventDispatcher{
            if(this._instance == null)this._instance = new MyEventDispatcher();
            return this._instance;
		}
	}
}
